package com.csgc.camera.http.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.csgc.camera.bean.BindPhoneParams
import com.csgc.camera.bean.ChooseMaskStyle
import com.csgc.camera.bean.CodeLoginParams
import com.csgc.camera.bean.FeedBackParams
import com.csgc.camera.bean.SendCodeParams
import com.csgc.camera.bean.UserInfo
import com.csgc.camera.bean.UserInfoParams
import com.csgc.camera.bean.VipPayParams
import com.csgc.camera.bean.VipQuanyiData
import com.csgc.camera.bean.VipType
import com.csgc.camera.bean.VipTypeParams
import com.csgc.camera.bean.WxBindParams
import com.csgc.camera.bean.WxLoginParams
import com.csgc.camera.bean.WxPayInfoData
import com.csgc.camera.http.ResponseLiveData
import com.csgc.camera.http.repository.AppRepository
import com.cysd.spsyxj.R
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch

class AppViewModel:ViewModel() {

    private val repository:AppRepository by lazy {
        AppRepository()
    }


    //登录user
    val userResult: ResponseLiveData<UserInfo> by lazy{
        ResponseLiveData()
    }
    val userInfoResult: ResponseLiveData<UserInfo> by lazy{
        ResponseLiveData()
    }
    val cleanInfoResult: ResponseLiveData<Any> by lazy{
        ResponseLiveData()
    }
    val codeResult: ResponseLiveData<Any> by lazy{
        ResponseLiveData()
    }
    val vipTypeResult: ResponseLiveData<List<VipType>> by lazy{
        ResponseLiveData()
    }
    val aliPayInfo:ResponseLiveData<String> by lazy{
        ResponseLiveData()
    }

    val feedBackResult:ResponseLiveData<Any> by lazy{
        ResponseLiveData()
    }

    //绑定微信
    val bindWxResult: ResponseLiveData<UserInfo> by lazy{
        ResponseLiveData()
    }

    val bindPhoneResult: ResponseLiveData<UserInfo> by lazy{
        ResponseLiveData()
    }

    //微信支付信息
    val wxPayInfo:ResponseLiveData<WxPayInfoData> by lazy{
        ResponseLiveData()
    }




    fun loginByCode(params: CodeLoginParams){
        viewModelScope.launch {
            repository.loginByCode(params)
                .onStart {  }
                .collectLatest {
                    userResult.value = it
                }

        }

    }

    /**
     * 获取用户信息
     */
    fun getUserInfo(param: UserInfoParams){
        viewModelScope.launch {
            repository.getUserInfo(param)
                .collectLatest {
                    userInfoResult.value = it
                }
        }
    }


    /**
     * 注销账户
     */
    fun cleanUserInfo(param: UserInfoParams){
        viewModelScope.launch {

            repository.cleanUserInfo(param)
                .collectLatest {
                    cleanInfoResult.value = it
                }

        }
    }

    /**
     * 发送验证码
     */
    fun sendSmsCode(params: SendCodeParams){
        viewModelScope.launch {
            repository.sendSmsCode(params)
                .collectLatest {
                    codeResult.value = it
                }
        }
    }

    /**
     * 获取用户vip购买类型
     */
    fun getVipTypeList(params: VipTypeParams){
        viewModelScope.launch {
            repository.getVipType(params)
                .collectLatest {
                    vipTypeResult.value = it
                }
        }

    }

    /**
     * 支付宝支付信息
     */
    fun getVipPayInfo(params: VipPayParams){
        viewModelScope.launch {
            repository.getAliPayInfo(params)
                .collectLatest {
                    aliPayInfo.value = it
                }
        }

    }

    /**
     * 反馈
     */
    fun submitFeedBack(params: FeedBackParams){
        viewModelScope.launch {
            repository.submitFeedBack(params)
                .collectLatest {
                    feedBackResult.value = it
                }
        }


    }


    /**
     * 微信登录
     */

    fun loginByWx(params: WxLoginParams){
        viewModelScope.launch {
            repository.loginByWx(params)
                .collectLatest {
                    userResult.value = it
                }
        }
    }


    /**
     * 微信绑定
     */
    fun bindWx(params: WxBindParams){

        viewModelScope.launch {
            repository.bindWx(params)
                .collectLatest {
                    bindWxResult.value = it
                }
        }
    }

    /**
     * 手机号绑定
     */
    fun bindPhone(params: BindPhoneParams){
        viewModelScope.launch {

            repository.bindPhone(params)
                .collectLatest {
                    bindPhoneResult.value = it
                }

        }
    }


    /**
     * 支付宝支付信息
     */
    fun getWxPayInfo(params: VipPayParams){
        viewModelScope.launch {
            repository.getWxPayInfo(params)
                .collectLatest {
                    wxPayInfo.value = it
                }
        }

    }


    public fun getIdentityList(): List<ChooseMaskStyle> {
        return listOf(
            ChooseMaskStyle("管理员",1,0),
            ChooseMaskStyle("公司高层",2,1),
            ChooseMaskStyle("普通员工",3,2),
            ChooseMaskStyle("其他",4,3),
        )
    }


     //添加会员权益数据
     val getVipQuanYiList = listOf(
         VipQuanyiData(R.drawable.ic_vipquanyi_remove,"无水印","一键去除水印"),
         VipQuanyiData(R.drawable.ic_vipquanyi_ad,"去广告","告别广告打扰"),
         VipQuanyiData(R.drawable.ic_vipquanyi_edit,"水印编辑","解锁更多水印"),
         VipQuanyiData(R.drawable.ic_vipquanyi_video,"拼图汇报","汇报内容更全面"),

     )


}